package com.dsg.kf.socket.boot;

import java.io.IOException;
import java.util.Properties;

import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.impl.JobDetailImpl;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import com.dsg.kf.common.cache.JobFactory;

@Configuration
@ComponentScan(basePackages = { "com.dsg.kf.socket.handler", "com.dsg.kf.socket.service","com.dsg.kf.common.cache" })
public class Application {

	@Autowired
    JobFactory jobFactory;
	
    @Bean(value="scheduler")
    public Scheduler scheduler() throws IOException, SchedulerException {  
        SchedulerFactory schedulerFactory = new StdSchedulerFactory(quartzProperties());  
        Scheduler scheduler = schedulerFactory.getScheduler();  
        scheduler.start();  
        return scheduler;  
    } 
    /** 
     * 设置quartz属性 
     * @throws IOException 
     */  
    public Properties quartzProperties() throws IOException {  
        Properties prop = new Properties();  
        prop.put("quartz.scheduler.instanceName", "ServerScheduler");  
        prop.put("org.quartz.scheduler.instanceId", "AUTO");  
        prop.put("org.quartz.scheduler.skipUpdateCheck", "true");  
        prop.put("org.quartz.scheduler.instanceId", "NON_CLUSTERED");  
        prop.put("org.quartz.scheduler.jobFactory.class", "org.quartz.simpl.SimpleJobFactory"); 
        prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");  
        prop.put("org.quartz.threadPool.threadCount", "5");  
        return prop;  
    }
    
    @Bean
    public JobDetailImpl createJobDetailImpl() {
        return new JobDetailImpl();
    }
    
}